package logic

import (
	"cart/cart"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartUpdateLogic {
	return &CartUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CartUpdateLogic) CartUpdate(req *types.CartUpdateRequest) (resp *types.Response, err error) {
	// todo: 修改购物车
	update, err := l.svcCtx.CartRpc.CartUpdate(l.ctx, &cart.CartUpdateRequest{
		UserId:   req.UserId,
		GoodsId:  req.GoodsId,
		GoodsNum: req.GoodsNum,
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "购物车商品修改成功",
		Data: update,
	}, nil
}
